﻿using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace WebApplication1
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });


            ConfigureMapping(app);
        }












        #region 私有方法

        private void ConfigureMapping(IApplicationBuilder app)
        {
            app.Map("/maptest", HandleMapTest);//手工高亮

        }

        private void HandleMapTest(IApplicationBuilder app)
        {

            app.Use(async (context, next) =>//手工高亮
            {
                await Task.Run(()=>Console.WriteLine("Hello World"));//手工高亮
                await next.Invoke();//手工高亮
            });

            app.Use(async (context, next) =>
            {
                await Task.Run(() => Console.WriteLine("Hello from "));//手工高亮
                await next.Invoke();
            });

            app.Run(async context =>
            {
                await Task.Run(() => Console.WriteLine("Map Test Successful"));//手工高亮
            });
        }

        #endregion
    }
}
